package com.sk.bilibili.view.fragment.channel;

import android.content.Intent;

import com.alibaba.android.vlayout.DelegateAdapter;
import com.sk.bilibili.adapter.vlayout.BannerAdapter;
import com.sk.bilibili.adapter.vlayout.main.home.HeaderAdapter;
import com.sk.bilibili.adapter.vlayout.main.home.HotAdapter;
import com.sk.bilibili.adapter.vlayout.main.home.RefreshAdapter;
import com.sk.bilibili.adapter.vlayout.main.home.them.RecommendAdapter;
import com.sk.bilibili.bean.Them;
import com.sk.bilibili.bean.ThemBanner;
import com.sk.bilibili.callBack.BannerClickCallBack;
import com.sk.bilibili.callBack.ThemClickCallBack;
import com.sk.bilibili.callBack.TypeClickCallBack;
import com.sk.bilibili.model.fragment.channel.ThemModel;
import com.sk.bilibili.utils.IntentUtils;
import com.sk.bilibili.view.activity.ThemActivity;
import com.sk.bilibili.view.fragment.BaseTypeFragment;

import java.util.List;

public class ThemFragment extends BaseTypeFragment<ThemModel> implements BannerClickCallBack,
        ThemClickCallBack, TypeClickCallBack {

    public ThemFragment(Integer typeId) {
        super(typeId);
    }

    private BannerAdapter bannerAdapter;
    private RecommendAdapter recommendAdapter;
    private HotAdapter serialAdapter;
    private HotAdapter finishAdapter;
    private static final int THEM=0;
    private static final int SERIAL=1;
    private static final int FINISH=2;

    @Override
    protected void initAdapter(DelegateAdapter adapter) {
        bannerAdapter = new BannerAdapter(getContext(), this);
        adapter.addAdapter(bannerAdapter);
        adapter.addAdapter(new HeaderAdapter(getContext(),"番剧推荐"));
        recommendAdapter = new RecommendAdapter(getContext(), this);
        adapter.addAdapter(recommendAdapter);
        RefreshAdapter refreshAdapter = new RefreshAdapter(getContext(), "换一换");
        refreshAdapter.setType(this,THEM);
        adapter.addAdapter(refreshAdapter);
        adapter.addAdapter(new HeaderAdapter(getContext(),"连载推荐"));
        serialAdapter = new HotAdapter(getContext(), this);
        adapter.addAdapter(serialAdapter);
        refreshAdapter=new RefreshAdapter(getContext(),"换一换");
        refreshAdapter.setType(this,SERIAL);
        adapter.addAdapter(refreshAdapter);
        adapter.addAdapter(new HeaderAdapter(getContext(),"完结推荐"));
        finishAdapter = new HotAdapter(getContext(), this);
        adapter.addAdapter(finishAdapter);
        refreshAdapter=new RefreshAdapter(getContext(),"换一换");
        refreshAdapter.setType(this,FINISH);
        adapter.addAdapter(refreshAdapter);
    }

    @Override
    public void onRefresh() {
        model.refresh(typeId);
    }

    @Override
    public void onBannerClick(String url) {
        IntentUtils.startUrl(getContext(),url);
    }

    public void loadBannerSuccess(List<ThemBanner> themBanners) {
        bannerAdapter.setList(themBanners);
        cancelRefresh();
    }

    @Override
    public void onThemClick(Integer themId, int selection) {
        ThemActivity.start(getContext(),themId,selection);
    }

    public void loadRecommendSuccess(List<Them> list) {
        recommendAdapter.setData(list);
    }

    public void loadSerialSuccess(List<Them> list) {
        serialAdapter.setData(list);
    }

    public void loadFinishSuccess(List<Them> list) {
        finishAdapter.setData(list);
    }

    @Override
    public void onFollowClick(Integer id) {
        model.followThem(id);
    }

    @Override
    public void onTypeClick(int pos) {
        switch (pos){
            case THEM:model.refreshThem(typeId);break;
            case SERIAL:model.refreshSerial(typeId);break;
            case FINISH:model.refreshFinish(typeId);break;
        }
    }

    public void followThemSuccess() {
        toast("自己追的番一定要看完欧");
    }

}